package com.example.back.mapper;

import com.example.back.entity.ShouCang;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.ArrayList;

@Mapper
public interface ShouCangMapper {
    @Insert("insert into collection(userId,postId,time) values(#{userId},#{postId},#{time})")
    int addShouCang(ShouCang shouCang);

    @Delete("delete from collection where id=#{id}")
    int deleteShouCangById(Serializable id);

    /**
     * 仅支持修改收藏时间
     */
    @Update("update collection set time=#{time} where id=#{id}")
    int updateShouCang(ShouCang shouCang);

    @Select("select id,userId,postId,time from collection where id=#{id}")
    ShouCang selectShouCangById(Serializable id);

    @SelectProvider(type = ShouCangMapperProvider.class, method = "getSelectShouCangSql")
    ArrayList<ShouCang> selectShouCang(ShouCang shouCang);

    //================
    @Select("select id from collection where userId=#{userId} and postId=#{postId}")
    Integer selectIdByUserAndPost(@Param("userId") Integer userId, @Param("postId") Integer postId);

    @Select("select count(1) from collection where userId=#{userId} and postId=#{postId}")
    int countByUserAndPost(@Param("userId") Integer userId, @Param("postId") Integer postId);

    @Select("select count(*) from collection where postId=#{param1}")
    int countShouCangByPostId(Integer postId);
}
